% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math} % this also loads fontspec
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
  % xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\usepackage[margin=1in]{geometry}
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
  pdftitle={长尾现象与基因矩阵的对比.R},
  pdfauthor={35139},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}

\title{长尾现象与基因矩阵的对比.R}
\author{35139}
\date{2024-04-10}

\begin{document}
\maketitle

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{library}\NormalTok{(tidyverse)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Warning: 程辑包'tidyverse'是用R版本4.3.3 来建造的
\end{verbatim}

\begin{verbatim}
## -- Attaching core tidyverse packages ------------------------ tidyverse 2.0.0 --
## v dplyr     1.1.4     v readr     2.1.4
## v forcats   1.0.0     v stringr   1.5.1
## v ggplot2   3.4.4     v tibble    3.2.1
## v lubridate 1.9.3     v tidyr     1.3.0
## v purrr     1.0.2     
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## i Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{PX }\OtherTok{=} \FunctionTok{c}\NormalTok{(}\DecValTok{18}\NormalTok{,}\DecValTok{20}\NormalTok{,}\DecValTok{22}\NormalTok{,}\DecValTok{46}\NormalTok{,}\DecValTok{48}\NormalTok{,}\DecValTok{50}\NormalTok{,}\DecValTok{52}\NormalTok{,}\DecValTok{54}\NormalTok{)}

\ControlFlowTok{for}\NormalTok{(p }\ControlFlowTok{in}\NormalTok{ PX)\{}
\NormalTok{  files }\OtherTok{=} \FunctionTok{str\_c}\NormalTok{(}\StringTok{"../"}\NormalTok{,p)}
  
\NormalTok{  file\_names }\OtherTok{=}\NormalTok{ fs}\SpecialCharTok{::}\FunctionTok{dir\_ls}\NormalTok{(files,}\AttributeTok{regexp =} \StringTok{"txt$"}\NormalTok{)}
\NormalTok{  result }\OtherTok{=} \FunctionTok{read\_table}\NormalTok{(file\_names,}\AttributeTok{show\_col\_types =}\NormalTok{ F,}\AttributeTok{col\_names =}\NormalTok{ F) }\SpecialCharTok{\%\textgreater{}\%} 
    \FunctionTok{set\_names}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\StringTok{"基因位点"}\NormalTok{,}\StringTok{"突变数量"}\NormalTok{))}
  
\NormalTok{  genemat }\OtherTok{=} \FunctionTok{read\_table}\NormalTok{(}\FunctionTok{str\_c}\NormalTok{(}\StringTok{"../genemat\_"}\NormalTok{,p,}\StringTok{".txt"}\NormalTok{),}\AttributeTok{show\_col\_types =}\NormalTok{ F,}\AttributeTok{col\_names =}\NormalTok{ F) }\SpecialCharTok{\%\textgreater{}\%} 
    \FunctionTok{mutate}\NormalTok{(}
      \AttributeTok{sums =} \FunctionTok{rowSums}\NormalTok{(.),}
      \StringTok{"基因位点"} \OtherTok{=} \DecValTok{1}\SpecialCharTok{:}\FunctionTok{n}\NormalTok{()}
\NormalTok{      )}
  
\NormalTok{  v }\OtherTok{=} \FunctionTok{left\_join}\NormalTok{(result,genemat,}\AttributeTok{by =} \StringTok{"基因位点"}\NormalTok{) }\SpecialCharTok{\%\textgreater{}\%} 
    \FunctionTok{head}\NormalTok{(}\DecValTok{30}\NormalTok{)}
  \FunctionTok{print}\NormalTok{(}\FunctionTok{str\_c}\NormalTok{(}\StringTok{"基因概率为:"}\NormalTok{,p))}
  \FunctionTok{print}\NormalTok{(v)}
\NormalTok{\}}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## [1] "基因概率为:18"
## # A tibble: 30 x 22
##    基因位点 突变数量    X1    X2    X3    X4    X5    X6    X7    X8    X9   X10
##       <dbl>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1     1318    39050     0     0     1     0     0     0     0     0     0     0
##  2     2599    21286     0     0     1     0     0     0     0     0     0     0
##  3     2211    20235     0     0     1     1     0     0     0     0     0     0
##  4     1877    15938     0     0     1     0     0     0     0     0     0     0
##  5     2781    14662     0     0     1     0     0     0     0     0     0     0
##  6     1408    14305     0     0     1     0     0     0     0     0     0     0
##  7     2856    10827     0     0     1     0     0     0     0     0     0     0
##  8      236    10679     0     0     0     0     0     0     0     1     0     0
##  9     1215    10674     0     0     1     0     0     0     0     0     0     0
## 10     1975     9797     0     0     1     0     0     0     0     0     0     0
## # i 20 more rows
## # i 10 more variables: X11 <dbl>, X12 <dbl>, X13 <dbl>, X14 <dbl>, X15 <dbl>,
## #   X16 <dbl>, X17 <dbl>, X18 <dbl>, X19 <dbl>, sums <dbl>
## [1] "基因概率为:20"
## # A tibble: 30 x 22
##    基因位点 突变数量    X1    X2    X3    X4    X5    X6    X7    X8    X9   X10
##       <dbl>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1      604   166470     0     0     1     0     0     0     0     0     0     0
##  2      972   145316     0     0     1     0     0     0     0     0     0     0
##  3     2808   125890     0     0     1     0     0     0     0     0     0     0
##  4      962   116856     0     1     0     0     0     0     0     0     0     0
##  5     2126    97475     0     0     1     0     0     0     0     0     0     0
##  6     1500    92299     0     1     0     0     0     0     0     0     0     0
##  7      251    82332     0     0     1     0     0     0     0     0     0     0
##  8      390    71843     0     0     1     0     0     0     0     0     0     0
##  9      655    68725     0     0     1     0     0     0     0     0     0     0
## 10     1608    47235     0     0     1     0     0     0     0     0     0     0
## # i 20 more rows
## # i 10 more variables: X11 <dbl>, X12 <dbl>, X13 <dbl>, X14 <dbl>, X15 <dbl>,
## #   X16 <dbl>, X17 <dbl>, X18 <dbl>, X19 <dbl>, sums <dbl>
## [1] "基因概率为:22"
## # A tibble: 30 x 22
##    基因位点 突变数量    X1    X2    X3    X4    X5    X6    X7    X8    X9   X10
##       <dbl>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1      683    98045     0     0     1     0     1     0     0     0     0     0
##  2     1878    96188     0     0     1     0     0     0     0     0     0     0
##  3     2344    76081     0     1     0     0     0     0     0     0     0     0
##  4       52    60633     0     0     1     0     0     0     0     0     0     0
##  5     1580    58726     0     0     1     0     0     0     0     0     0     0
##  6     2240    43324     0     0     1     0     0     0     0     0     0     0
##  7     1709    29912     0     0     1     0     0     0     0     0     0     0
##  8     2906    26964     0     0     1     0     0     0     0     0     0     0
##  9     2742    23444     0     0     1     0     0     0     0     0     0     0
## 10     2022    22495     0     0     1     0     0     0     0     0     0     0
## # i 20 more rows
## # i 10 more variables: X11 <dbl>, X12 <dbl>, X13 <dbl>, X14 <dbl>, X15 <dbl>,
## #   X16 <dbl>, X17 <dbl>, X18 <dbl>, X19 <dbl>, sums <dbl>
## [1] "基因概率为:46"
## # A tibble: 30 x 22
##    基因位点 突变数量    X1    X2    X3    X4    X5    X6    X7    X8    X9   X10
##       <dbl>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1     2205   153295     0     1     0     0     0     0     0     0     0     0
##  2      572   135042     0     1     0     0     0     0     0     0     0     0
##  3     2409   134248     0     0     1     0     0     0     0     0     0     0
##  4      997    81013     0     0     1     0     0     0     0     0     0     0
##  5     1114    66587     0     0     1     0     0     0     0     0     0     0
##  6     1665    56015     0     0     1     0     0     0     0     0     0     0
##  7     1390    51324     0     0     1     1     0     0     0     0     0     0
##  8     1432    49440     1     0     1     0     0     1     0     0     0     0
##  9     2912    48891     0     0     1     0     0     0     0     0     0     0
## 10     2417    38235     0     0     1     0     0     0     0     0     0     0
## # i 20 more rows
## # i 10 more variables: X11 <dbl>, X12 <dbl>, X13 <dbl>, X14 <dbl>, X15 <dbl>,
## #   X16 <dbl>, X17 <dbl>, X18 <dbl>, X19 <dbl>, sums <dbl>
## [1] "基因概率为:48"
## # A tibble: 30 x 22
##    基因位点 突变数量    X1    X2    X3    X4    X5    X6    X7    X8    X9   X10
##       <dbl>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1      750    33597     0     1     1     0     0     0     0     0     0     1
##  2     2838    32219     0     0     1     0     0     0     0     0     0     0
##  3     1505    32130     0     0     0     0     0     0     0     0     0     0
##  4       95    28484     0     0     1     0     0     0     0     0     0     0
##  5      449    20661     0     1     0     0     0     0     0     0     0     0
##  6     1399    19522     0     0     1     0     0     0     0     0     0     0
##  7     1597    17533     0     0     1     0     0     0     0     0     0     1
##  8     2069    17247     0     0     1     0     0     0     0     1     0     0
##  9     2091    16625     0     0     1     0     0     0     0     0     0     0
## 10     2265    16301     0     0     1     0     0     0     0     0     0     0
## # i 20 more rows
## # i 10 more variables: X11 <dbl>, X12 <dbl>, X13 <dbl>, X14 <dbl>, X15 <dbl>,
## #   X16 <dbl>, X17 <dbl>, X18 <dbl>, X19 <dbl>, sums <dbl>
## [1] "基因概率为:50"
## # A tibble: 30 x 22
##    基因位点 突变数量    X1    X2    X3    X4    X5    X6    X7    X8    X9   X10
##       <dbl>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1      997   539879     0     0     1     0     0     0     0     0     0     0
##  2     2989   537816     0     0     1     0     0     0     0     0     0     0
##  3     1846   531250     0     0     1     0     0     0     0     0     0     0
##  4     2183   522561     0     0     1     0     0     0     0     0     0     0
##  5     2834   495190     0     0     0     0     0     0     0     0     0     0
##  6     1724   476278     0     1     0     0     0     0     0     0     0     0
##  7      670   474715     0     0     0     0     0     0     0     0     0     0
##  8     2949   466284     0     1     0     0     1     0     0     0     0     0
##  9     1922   203072     0     0     1     0     0     0     0     0     1     0
## 10     1909   202873     0     0     1     0     0     0     0     0     0     1
## # i 20 more rows
## # i 10 more variables: X11 <dbl>, X12 <dbl>, X13 <dbl>, X14 <dbl>, X15 <dbl>,
## #   X16 <dbl>, X17 <dbl>, X18 <dbl>, X19 <dbl>, sums <dbl>
## [1] "基因概率为:52"
## # A tibble: 30 x 22
##    基因位点 突变数量    X1    X2    X3    X4    X5    X6    X7    X8    X9   X10
##       <dbl>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1      368    66563     0     0     1     0     0     0     0     0     0     0
##  2     2908    53069     0     0     1     1     0     1     0     0     0     0
##  3     2055    51766     0     0     1     0     0     0     0     1     0     1
##  4      375    49071     0     0     1     0     0     0     0     0     0     0
##  5      944    37364     0     0     1     0     0     0     0     0     0     0
##  6     1637    37328     0     0     1     0     0     0     0     0     0     0
##  7      129    34825     0     0     1     0     0     0     0     0     0     0
##  8     2504    34636     0     0     1     0     0     0     0     0     0     0
##  9       43    31170     0     0     1     0     0     0     0     0     0     0
## 10     1242    30921     0     0     1     0     0     0     0     0     0     0
## # i 20 more rows
## # i 10 more variables: X11 <dbl>, X12 <dbl>, X13 <dbl>, X14 <dbl>, X15 <dbl>,
## #   X16 <dbl>, X17 <dbl>, X18 <dbl>, X19 <dbl>, sums <dbl>
## [1] "基因概率为:54"
## # A tibble: 30 x 22
##    基因位点 突变数量    X1    X2    X3    X4    X5    X6    X7    X8    X9   X10
##       <dbl>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1     1159    60982     0     0     1     0     0     0     0     0     0     0
##  2      653    60921     0     0     1     0     0     0     0     0     0     0
##  3     2687    60579     0     0     1     0     0     0     0     1     0     1
##  4      860    58656     0     0     1     0     1     0     0     0     0     0
##  5      844    53140     0     0     1     0     0     0     0     0     0     0
##  6     2644    45916     0     1     0     0     0     0     0     0     0     0
##  7      517    37495     0     1     1     0     0     0     0     0     0     0
##  8      274    35566     0     0     1     0     0     0     0     0     0     0
##  9     1488    33004     0     0     1     1     0     0     0     0     0     0
## 10     1233    32590     0     1     0     1     0     0     0     0     0     0
## # i 20 more rows
## # i 10 more variables: X11 <dbl>, X12 <dbl>, X13 <dbl>, X14 <dbl>, X15 <dbl>,
## #   X16 <dbl>, X17 <dbl>, X18 <dbl>, X19 <dbl>, sums <dbl>
\end{verbatim}

\end{document}
